/**
 * 
 * @deprecated 判断字符串是否是{}()[]匹配的  考察的是栈 时间复杂度 O(n)  空间复杂度O(n)
 */

const Mymatch = (left: string, right: string) => {
    if (left === '(' && right === ')') {
        return true
    }
    if (left === '{' && right === '}') {
        return true
    }
    if (left === '[' && right === ']') {
        return true
    }
    return false
}


const mateBracket = (str: string) => {
    const leftbracket = '({['
    const rightbracket = ')}]'
    let stack = []

    for (let i = 0; i < str.length; i++) {
        const item = str[i]
        if (leftbracket.includes(item)) {
            stack.push(item)
        } else if (rightbracket.includes(item)) {
            const top = stack[stack.length - 1]
            console.log(top,item)
            if(Mymatch(top,item)){
                stack.pop()
            }else{
                return false
            }
        }
    }
    return stack.length === 0
}

console.log(mateBracket('(aa{rvr[)ccc}]scsc)'))